import request from '#/utils/requestAbort.js';
import { exportRequest } from '#/utils/request.js';
import { SERVER_URL_OBJ } from '../../../../config/urlConfig';

export function getList(data: any) {
  return request(`/configuration/fileStorage/getList`, {
    method: 'POST',
    data,
  });
}

export const uploadUrl = '/configuration/fileStorage/addDate';

export const getDownloadUrl = (fileId: string) => {
  const { CLIENT_ENV } = process.env;

  let url: string = (SERVER_URL_OBJ as any)[CLIENT_ENV as string];

  if (CLIENT_ENV === 'dev') {
    url = SERVER_URL_OBJ.test;
  }
  return `${url}/annex/annex/downLoadFile/${fileId}`;
};

export function downLoadFile(fileId: string) {
  return request(`/annex/annex/downLoadFile/${fileId}`, {
    method: 'GET',
    responseType: 'blob',
  });
}

export function delRow(id: string) {
  return request(`/configuration/fileStorage/deleteDate/${id}`, {
    method: 'GET',
  });
}

const dictionaryId = 793;

export function fetchFiletype(marketId?: string) {
  return request(`/configuration/fileStorage/listFileType`, {
    method: 'POST',
    data: { dictionaryId, marketId },
  });
}

export function createFiletype(params: any) {
  return request(`/dictionary/dictionaryValue/addDictionaryValue`, {
    method: 'POST',
    data: { dataResults: [{ id: '', dictionaryId, ...params }] },
  });
}

export function updateFiletype(params: any) {
  return request(`/dictionary/dictionaryValue/UpdateDictionary`, {
    method: 'POST',
    data: params,
  });
}

export function deleteFiletype(id: number) {
  return request(`/configuration/fileStorage/removeFileType/${id}`, {
    method: 'GET',
  });
}

export function getMarketList() {
  return request(`/dictionary/dictionaryValue/getDictionaryByCode/TJ_Data_Storage`, {
    method: 'GET',
  });
}
